<script>

/**
 * 构建工具栏
 *    props: { items: array<btn>, ...el-button-group }
 *    btn: { ...ym-button }
 */
export default {
  name: 'YmToolbar',
  functional: true,
  props: {
    items: {
      type: Array,
      default: () => []
    },
    row: {
      type: Object,
      default: () => ({})
    }
  },
  render (h, context) {
    const { props, data, listeners } = context
    return h('el-button-group', data, [...props.items.map((item) => {
      let row = props.row
      let disabled = item.disabled || (item.bind && props.row[item.bind] === false)
      let config = {
        size: 'small',
        ...item,
        disabled,
        row
      }
      return h('ym-button', {
        props: config,
        attrs: config,
        on: {
          ...listeners,
          click: () => {
            if (listeners.click) listeners.click(item, props.row)
          }
        }
      })
    }), ...(context.children || [])])
  }
}
</script>
